import dayjs from 'dayjs'
// import { constant, constantMap } from '@/utils/constant'

import relativeTime from 'dayjs/plugin/relativeTime'

dayjs.extend(relativeTime)

export function dateFormat(row, column, cellValue, index) {
  if (cellValue === undefined || cellValue === null) {
    return ''
  }
  return dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss')
}

export function dayjsFormat(val) {
  return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
}

export function ageFormat(row, column, cellValue, index) {
  if (cellValue) {
    const now = dayjs()
    const birthday = dayjs(cellValue)
    const age = now.year() - birthday.year()
    const offset =
      birthday.month() < now.month() && birthday.day() < now.day() ? 0 : 1
    return age + offset
  }
  return cellValue
}

// export function weightFormat(row, column, cellValue, index) {
//   return cellValue ? cellValue + ' kg' : ''
// }

export function genderFormat(row, column, cellValue, index) {
  return cellValue === 0 ? '男' : cellValue === 1 ? '女' : '未知'
}

// export function weightStateFormat(row, column, cellValue, index) {
//   return cellValue === 0 ? '未完成' : cellValue === 1 ? '完成' : ''
// }

export function stateFormat(row, column, cellValue, index) {
  return cellValue === 0 ? '禁用' : cellValue === 1 ? '正常' : ''
}

export function userStateFormat(row, column, cellValue, index) {
  return cellValue === 0 ? '冻结' : cellValue === 1 ? '正常' : ''
}

export function stateClassName(val) {
  return val === 0 ? 'cell-danger' : val === 1 ? 'cell-success' : ''
}

export function enableFormat(row, column, cellValue, index) {
  return cellValue === 0 ? '禁用' : cellValue === 1 ? '启用' : ''
}

export function yesFormat(row, column, cellValue, index) {
  return cellValue === 0 ? '否' : cellValue === 1 ? '是' : ''
}

// export function passCountLimitFormat(row, column, cellValue, index) {
//   return cellValue === constant.maxPassCount ? '无限制' : cellValue
// }

// export function passCountLimitClassName(val) {
//   // console.log(val, 'passCountLimitClassName')
//   return val === constant.maxPassCount ? 'cell-success' : 'cell-danger'
// }

// export function reserveTypeFormat(row, column, cellValue, index) {
//   return constantMap.reserveRuleTypeMap[cellValue] || ''
// }

// export function reserveTypeClassName(val) {
//   return val === 0
//     ? 'cell-success'
//     : val === 1
//     ? 'cell-primary'
//     : val === 2
//     ? 'cell-danger'
//     : ''
// }

// export function reserveStateFormat(row, column, cellValue, index) {
//   return constantMap.weightStateMap[cellValue] || ''
// }

// export function reserveStateClassName(val) {
//   return val === 0
//     ? 'cell-warn'
//     : val === 1
//     ? 'cell-primary'
//     : val === 2
//     ? 'cell-danger'
//     : val === 12
//     ? 'cell-success'
//     : ''
// }

// export function weightTypeFormat(row, column, cellValue, index) {
//   return constantMap.weightTypeMap[cellValue] || ''
// }

// export function weightTypeClassName(val) {
//   return val === 1 ? 'cell-info' : val === 2 ? 'cell-primary' : ''
// }

// export function deviceStateFormat(row, column, cellValue, index) {
//   return constantMap.deviceStateMap[cellValue] || ''
// }

// export function deviceStateClassName(val) {
//   return val === 1 ? 'cell-success' : val === 0 ? 'cell-danger' : ''
// }

// export function deviceAlertStateFormat(row, column, cellValue, index) {
//   return constantMap.deviceAlertStateMap[cellValue] || ''
// }

// export function deviceAlertStateClassName(val) {
//   return val === 1 ? 'cell-success' : val === 0 ? 'cell-danger' : ''
// }

// export function flowTypeFormat(row, column, cellValue, index) {
//   return constantMap.flowTypeMap[cellValue] || ''
// }

// export function syncStatusFormat(row, column, cellValue, index) {
//   return constantMap.syncStatusMap[cellValue] || ''
// }

// export function syncStatusStateClassName(val) {
//   return val === 100
//     ? 'cell-success'
//     : val === 99
//     ? 'cell-danger'
//     : val === 1
//     ? 'cell-primary'
//     : 'cell-info'
// }
